/**
 * 支出控制器
 * fanqunxing
 */
const accountService = require('../service/accountService');
const { cloud, getOpenid } = require('../dbCloud');

const sendAddAccountMsg = () => {
  cloud.openapi.subscribeMessage.send({
    touser: getOpenid(),
    page: 'index',
    lang: 'zh_CN',
    data: {
      thing3: {
        value: '339208499'
      },
      time1: {
        value: '2015年01月05日'
      }
    },
    templateId: 'HjeQIg5dw0WHq7VINKhGL0BDWToX1ElpeWbFcmF8-fo',
    miniprogramState: 'developer'
  });
};

/**
 * 获取支出
 */
const queryAccounts = async (request) => {
  return accountService.queryAccounts(request);
}

/**
 * 支出总和
 */
const queryTotalAccount = async (request) => {
  // setTimeout(() => {
  //   sendAddAccountMsg();
  // }, 100);
  return accountService.queryTotalAccount(request);
};


/**
 * 根据主键查询支出
 */
const queryAccountById = async (request) => {
  return accountService.queryAccountById(request);
};

/**
 * 根据主键删除支出
 */
const deleteAccountById = async (request) => {
  return accountService.deleteAccountById(request);
};

/**
 * 获取各个类型总和
 */
const getAllTypeCount = async (request) => {
  return accountService.getAllTypeCount(request);
};

/**
 * 新增账单
 */
const addAccout = async (request) => {
  return accountService.addAccout(request);
}

module.exports = {
  queryAccounts,
  queryAccountById,
  deleteAccountById,
  getAllTypeCount,
  addAccout,
  queryTotalAccount
}